﻿Imports System.Data.SqlClient
Public Class clsProducto
  Private cnDB As SqlConnection

  Public Sub New(ByVal psConnectString As String)
    cnDB = New SqlConnection(psConnectString)
  End Sub

  Public Function ProductoListar(ByVal pbCodProd As Boolean, ByVal pvFiltro As String) As DataTable
    Dim sqlCmd As New SqlClient.SqlCommand
    Dim oSqlda As SqlDataAdapter
    Dim oDataTable As New DataTable
    Try
      sqlCmd.Connection = cnDB
      sqlCmd.CommandType = CommandType.StoredProcedure
      sqlCmd.CommandText = "spProductoListar"
      sqlCmd.Parameters.Add("@pbCodProd", SqlDbType.Bit).Value = pbCodProd
      sqlCmd.Parameters.Add("@pvFiltro", SqlDbType.VarChar, 30).Value = pvFiltro
      cnDB.Open()

      oSqlda = New SqlDataAdapter(sqlCmd)
      oSqlda.Fill(oDataTable)
      oSqlda.Dispose()
      sqlCmd.Dispose()

      Return oDataTable

    Catch ex As Exception
      Throw
    Finally
      If cnDB.State = ConnectionState.Open Then cnDB.Close()
    End Try
  End Function
End Class
